<!-- 页面外套 -->
<div class="page-wrapper" id="setup_business_return">

    <!-- 面板盒子 -->
    <br><div class="panel">
        <div class="panel-heading">回访最长周期设置</div>
        <div class="panel-body">

            <form class="form-horizontal" style="max-width:300px">

                <!-- 信息员 -->
                <div class="form-group">
                    <label class="col-sm-4">信息员</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <select class="form-control">
                                <option value="A">A</option>
                                <option value="B">B</option>
                                <option value="C">C</option>
                                <option value="D">D</option>
                                <option value="E">E</option>
                            </select>
                            <span class="input-group-addon fix-border fix-padding"></span>
                            <ul>
                                <li><input type="number" class="form-control" name="providerA"></li>
                                <li class="hide"><input type="number" class="form-control" name="providerB"></li>
                                <li class="hide"><input type="number" class="form-control" name="providerC"></li>
                                <li class="hide"><input type="number" class="form-control" name="providerD"></li>
                                <li class="hide"><input type="number" class="form-control" name="providerE"></li>
                            </ul>
                            <span class="input-group-addon">天</span>
                        </div>
                    </div>
                </div>

                <!-- 业务正跟踪 -->
                <div class="form-group">
                    <label class="col-sm-4">业务正跟踪</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input type="number" class="form-control" name="trackedA">
                            <span class="input-group-addon">天</span>
                        </div>
                    </div>
                </div>

                <!-- 业务在谈 -->
                <div class="form-group">
                    <label class="col-sm-4">业务在谈</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <select class="form-control">
                                <option value="A">A</option>
                                <option value="B">B</option>
                                <option value="C">C</option>
                                <option value="D">D</option>
                                <option value="E">E</option>
                            </select>
                            <span class="input-group-addon fix-border fix-padding"></span>
                            <ul>
                                <li><input type="number" class="form-control" name="businessA"></li>
                                <li class="hide"><input type="number" class="form-control" name="businessB"></li>
                                <li class="hide"><input type="number" class="form-control" name="businessC"></li>
                                <li class="hide"><input type="number" class="form-control" name="businessD"></li>
                                <li class="hide"><input type="number" class="form-control" name="businessE"></li>
                            </ul>
                            <span class="input-group-addon">天</span>
                        </div>
                    </div>
                </div>

                <!-- 设计在谈 -->
                <div class="form-group">
                    <label class="col-sm-4">设计在谈</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <select class="form-control">
                                <option value="A">A</option>
                                <option value="B">B</option>
                                <option value="C">C</option>
                                <option value="D">D</option>
                                <option value="E">E</option>
                            </select>
                            <span class="input-group-addon fix-border fix-padding"></span>
                            <ul>
                                <li><input type="number" class="form-control" name="designerA"></li>
                                <li class="hide"><input type="number" class="form-control" name="designerB"></li>
                                <li class="hide"><input type="number" class="form-control" name="designerC"></li>
                                <li class="hide"><input type="number" class="form-control" name="designerD"></li>
                                <li class="hide"><input type="number" class="form-control" name="designerE"></li>
                            </ul>
                            <span class="input-group-addon">天</span>
                        </div>
                    </div>
                </div>
                
                <!-- 提交按钮 -->
                <div class="form-group">
                    <div class="col-sm-4"></div>
                    <div class="col-sm-8 text-right"><button type="button" class="btn btn-primary">提交</button></div>
                </div>

            </form>

        </div>
    </div>

</div>
<!-- page-wrapper -->

<script>
$(function(){
    
    // 变量声明
    var setup_business_return_form = $('#setup_business_return form');
    var setup_business_return_api = {
        show : LOCAL + "Test/Setup/Business/return_show.json",
        save : API.test_response,
    }

    // 表单赋值(调用)
    setup_business_return_show();

    // 表单提交
    setup_business_return_form.find('button').click(function(){
        // var data = um_data_get( setup_business_return_form );
        var data = JSON.stringify([
            {   "vlx":0,
                "mlevel": setup_business_return_form.find('.form-group').eq(0).find('select').val(),
                "vmaxDay":setup_business_return_form.find('.form-group').eq(0).find('li:visible input').val()
            },
            {   "vlx":1,
                "mlevel": "A",
                "vmaxDay":setup_business_return_form.find('.form-group').eq(1).find('input').val()
            },
            {   "vlx":2,
                "mlevel": setup_business_return_form.find('.form-group').eq(2).find('select').val(),
                "vmaxDay":setup_business_return_form.find('.form-group').eq(2).find('li:visible input').val()
            },
            {   "vlx":3,
                "mlevel": setup_business_return_form.find('.form-group').eq(3).find('select').val(),
                "vmaxDay":setup_business_return_form.find('.form-group').eq(3).find('li:visible input').val()
            }
        ]);
        // 远程提交
        $.ajax({
            url : setup_business_return_api.save,
            type : 'post',
            data : {
                json : data
            },
            success : function(data){
                if( data.status==1 ){
                    um_tip(data.message);
                    setTimeout(function(){
                        setup_business_return_form[0].reset(); // 表单重置
                        setup_business_return_show(); // 表单赋值(调用)
                    }, 1500);
                } else {
                    um_tip(data.message,"1500","text-danger");
                }
            }
        });
    });

    // select影响右侧input显示与隐藏
    setup_business_return_form.find('select').change(function(e){
        var selectVal = 0;
        switch( $(this).val() ){
            case 'A': selectVal = 1; break;
            case 'B': selectVal = 2; break;
            case 'C': selectVal = 3; break;
            case 'D': selectVal = 4; break;
            case 'E': selectVal = 5; break;
        }
        var allLi = $(this).siblings('ul').find('li');
        var theLi = allLi.eq( selectVal -1 );
        allLi.addClass('hide');
        theLi.removeClass('hide');
    });

    // 表单赋值(封装)
    function setup_business_return_show(){
        $.ajax({
            url : setup_business_return_api.show,
            type : 'post',
            data : {},
            success : function(data){
                var data = data.data;
                um_data_set( setup_business_return_form, data ); //表单赋值
            }
        });
    }

});//预加载结尾
</script>